package edu.ucsd.cse135.gas.action.reviewer;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import edu.ucsd.cse135.gas.bean.reviewer.ReviewBean;
import edu.ucsd.cse135.gas.logic.Degree;
import edu.ucsd.cse135.gas.logic.applicant.Applicant;
import edu.ucsd.cse135.gas.logic.reviewer.ReviewerFunctions;
import edu.ucsd.cse135.gas.resources.Constants;

public class ShowApplicationAction extends Action {

	public ShowApplicationAction() {
		super();
	}
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
		
			ReviewBean reviewBean = (ReviewBean)form;
			
			String applicantParameter = reviewBean.getApplicant();
		
			HashMap<String, Object> application = ReviewerFunctions.showApplication(applicantParameter);
			
			request.getSession().setAttribute("applicant", (Applicant)application.get("applicant"));
			
			request.getSession().setAttribute("degrees", (ArrayList<Degree>)application.get("degrees"));
			
			request.getSession().setAttribute("reviews", (ArrayList<ReviewBean>)application.get("reviews"));
			
			return mapping.findForward(Constants.SUCCESS);	
		
	}
}
